package com.gzk.oeno.ihm.tables.renderer;

import java.awt.Component;
import java.util.Collection;

import javax.swing.Icon;
import javax.swing.JTable;

public class CollectionCellRenderer extends CenteredCellRenderer {

	private final Icon filledIcon;
	private final Icon emptyIcon;
	
	public CollectionCellRenderer(Icon filledIcon, Icon emptyIcon){
		super();
		this.filledIcon = filledIcon;
		this.emptyIcon = emptyIcon;
	}
	
	
	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
				row, column);
		

		if (value == null || value instanceof Collection<?>){
			Collection<?> coll = null;
			if (value != null){
				coll = (Collection<?>) value;
			}
			setText(null);
			setIcon(coll == null || coll.isEmpty() ? emptyIcon : filledIcon);
			setToolTipText(buildToolTip(coll));
		}
		return this;
	}
	
	// Can be overwrited
	protected String buildToolTip(@SuppressWarnings("unused") Collection<?> value){
		return null;
	}
}
